package cl.rizepe.playntest.core.listeners;

import playn.core.Image;
import playn.core.ImageLayer;
import playn.core.Pointer.Event;
import playn.core.Pointer.Listener;
import pythagoras.f.Point;
import cl.rizepe.playntest.core.effects.EffectFactory;
import cl.rizepe.playntest.core.views.EffectedLayer;

public class DragMove implements Listener {
	float xStart,yStart;
	float xRelativeStart,yRelativeStart;
	EffectedLayer layerState;
	ImageLayer layerShadow=null;
	Image image;
	float alphaShadow;
	float scale=1;
	public DragMove (EffectedLayer layer){
		this.layerState=layer;
		
	}
	
	public DragMove (EffectedLayer layer, Image image, float alphaShadow){
		this(layer);
	    this.image=image;
	    this.alphaShadow=alphaShadow;
	}
	
	@Override
	public void onPointerStart(Event event) {
		//pythagoras.f.Transform transform=layerState.getImageLayer().transform();
		Point translate=layerState.getTranslate();
		xStart=event.x();
		yStart=event.y();
		xRelativeStart=translate.x();
		yRelativeStart=translate.y();
		layerShadow=EffectFactory.createShadow(layerState, image, alphaShadow, scale);
		layerShadow.setVisible(true);
	}


	@Override
	public void onPointerDrag(Event event) {
		    layerShadow.setTranslation(
					xRelativeStart+event.x()-xStart, 
					yRelativeStart+event.y()-yStart);
		
	}

	@Override
	public void onPointerEnd(Event event) {
		layerState.setTranslation(
				xRelativeStart+event.x()-xStart, 
				yRelativeStart+event.y()-yStart);

	    layerShadow.setVisible(false);
	    layerState.updateEffects();
	}
}
